package Week3.J0502;

import java.util.*;

public class 神奇数_xv {

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 11; i < 100; i++) {
            boolean isPrime = true;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime) list.add(i);
        }
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int cnt = 0;
        for (int i = a; i <= b; i++) {
            String s = String.valueOf(i);
            for (Integer e : list) {
                String s1 = String.valueOf(e / 10);
                String s2 = String.valueOf(e % 10);
                if (!s1.equals(s2)) {
                    if (s.contains(s1) && s.contains(s2)) {
                        cnt++;
                        break;
                    }
                } else {
                    int index = s.indexOf(s1);
                    if (index != -1 && s.indexOf(s2, index + 1) != -1) {
                        cnt++;
                        break;
                    }
                }
            }
        }
        System.out.println(cnt);
    }
}

